const Koa = require("koa")
const serve = require("koa-static")
const proxy = require("koa2-proxy-middleware")
const app = new Koa()
// 这句话 的意思是除接口之外所有的请求都发送给了 index.html

app.use(
  proxy({
    targets: {
      // (.*) means anything
      "/prod-api/(.*)": {
        target: "http://ihrm-java.itheima.net", //后端服务器地址
        changeOrigin: true,
        pathRewrite: {
          "/prod-api": "/api"
        }
      }
    }
  })
)
const { historyApiFallback } = require("koa2-connect-history-api-fallback")
app.use(
  historyApiFallback({
    whiteList: ["/prod-api"]
  })
)

app.use(serve(__dirname + "/dist")) //将public下的代码静态化

app.listen(3333, () => {
  console.log("http://127.0.0.1:3333  人资项目启动")
})
